Variable Cross Reference for Applesoft Programs

Besides illustrating a lot of programming techniques, the VCR program is a very useful tool when you are writing large Applesoft programs.  As listed here, it requires a 48K Apple, and assumes that HIMEM is set to at least $8AA7.  You BRUN it, and it sets up the &-vector.  When you are ready to print a cross reference, you merely type "&" and a carriage return, and out it comes.  It is VERY fast:  about 15 times faster than the VCR program included in Apple's DOS Tool Kit.  It also takes less memory than Apple's version, both for the program itself and for the tables it constructs during execution.

The main body of the program is in lines 1400 thru 1460.  After calling INITIALIZATION, the subroutine PROCESS.LINE is called until there are no more lines.  Then PRINT.REPORT is called, and finally INITIALIZATION is called again to restore Applesoft's tables to their original form.

INITIALIZATION sets up PNTR to point to the beginning of the program, and EOT to point to the end of the table area.  It also clears out a set of 26 two-byte pointers in HSHTBL (hash table).  PROCESS.ONE scans a single line looking for variables by calling SCAN.FOR.VARIABLES, until the end of the program is reached.  PRINT.REPORT merely prints a nice orderly report from the data which has been stored in the table by SCAN.FOR.VARIABLES.

The symbol table routines used in VCR are very similar to the ones used inside S-C Assembler II Version 4.0.  There are 26 pointers starting at HSHTBL ($280), each one representing one letter of the alphabet.  The first letter of a variable name selects one of these pointers.  The pointer points at the first entry in a chain of variable names.  When a new variable name is found, it is inserted in the appropriate chain at the place where it will be in alphabetical order.  A sub-chain is kept for each variable name of all the line numbers from which it is referenced.  The line number chain is maintained in numerical order.  Thus there is no sorting necessary when it comes time to print the report.

Since no routines from the Applesoft ROMs are used, VCR will work with no changes with the RAM version of Aplesoft.  Since it loads below $9000, it will not conflict with Neil Konzen's PLE (Program Line Editor).  Since it is just straight-forward code, with no address tables or embedded data, you can easily relocate it to a different running address; only the 3-byte instructions with the third byte equal to $88, $89, or $8A need to be changed.  Or, you can type it in, and use a different origin (line 1040).

If you like to modify programs, this one needs one improvement.  (Only one?)  I forgot to take note of the FN token, so any FN definitions or uses will look like references to an array variable.  Another kind of modification, called "major" perhaps, will turn the VCR into LNCR (Line Number Cross Reference).
